﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;

namespace Duoease.ContainerModel.Entity
{
    public class FridgeModel : BaseModel
    {      
        /**
         * 功能：绘制标签
         * 
         * */
        public override void AffixToLabel(Label oldLabel, int width, int height)
        {
            Label newLabel = new Label();

            this.panel.Controls.Clear();
            this.panel.Controls.Add(oldLabel);
            for (int i = 0; i < this.Row; i++)
            {
                for (int j = 0; j < this.Column; j++)
                {
                    newLabel = new Label();
                    newLabel.Width = 42;
                    newLabel.Text = ((i + 1) * 10 + j + 1).ToString();
                    newLabel.Font = new Font(newLabel.Font.FontFamily, 20, FontStyle.Bold);

                    newLabel.MouseDown += new MouseEventHandler(this.View.InewLabel_MouseDown);
                    newLabel.ForeColor = Color.Black;
                    newLabel.BackColor = Color.Transparent;
                    this.ContainerWidth = width;
                    this.ContainerHeight = height;
                    newLabel.Location = new Point(this.Location.X + this.UnitWidth * j + this.UnitWidth / 2 - 10, this.Location.Y + this.UnitHeight * i + this.UnitHeight / 2 - 10);
                    // newLabel.Parent = this.splitContainer1.Panel1;
                    this.panel.Controls.Add(newLabel);
                }
            }
        }

        /**
         * 功能：鼠标点击事件
         * 
         * */
        public override void OnMouseClickHandler(object sender, MouseEventArgs e)
        {
             Point p = new Point(e.X, e.Y);
             int x = 0;
             int y = 0;
             Point origin = Location;
             g = this.panel.CreateGraphics();

             if (e.X >= origin.X && e.X <= origin.X + UnitWidth * Column && e.Y >= origin.Y && e.Y <= origin.Y + UnitHeight * Row)
             {
                    for (int i = 0; i < Column; i++)
                    {
                        if (p.X >= origin.X + i * UnitWidth && p.X <= origin.X + (i + 1) * UnitWidth)
                        {
                            x = i + 1;
                            break;
                        }
                    }
                    for (int i = 0; i < Row; i++)
                    {
                        if (p.Y >= origin.Y + i * UnitHeight && p.Y <= origin.Y + (i + 1) * UnitHeight)
                        {
                            y = i + 1;
                            break;
                        }
                    }
                    // this.g = this.View.g;
                    Draw();
                    Render(g, new Point(origin.X + (x - 1) * UnitWidth, origin.Y + (y - 1) * UnitHeight), UnitWidth, UnitHeight, Alpha, Color.Blue);

                    this.View.MouseRow = y;
                    this.View.MouseColumn = x;
             }
        }
    }
}
